//
// Created by lingzhitech on 25-9-18.
//

#include "QueryResult.h"
std::string make_plural(size_t ctr, const std::string& word,
                        const std::string& ending)
{
    return (ctr > 1) ? word + ending : word;
}


std::ostream &print(std::ostream &os, const QueryResult &qr) {
    // if the word was found, print the count and all occurrences
    os << qr.sought << " occurs " << qr.lines->size() << " "
            << make_plural(qr.lines->size(), "time", "s") << std::endl;
    // print each line in which the word appeared
    for (auto num: *qr.lines) // for every element in the set
        // don't confound the user with text lines starting at 0
            os << "\t(line " << num + 1 << ") "
                    << *(qr.file->begin() + num) << std::endl;
    return os;
}